package com.springapi.service.impl;

import com.springapi.entity.Goodsclass;
import com.springapi.dao.GoodsclassDao;
import com.springapi.service.GoodsclassService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类(Goodsclass)表服务实现类
 *
 * @author makejava
 * @since 2024-12-17 11:49:34
 */
@Service("goodsclassService")
public class GoodsclassServiceImpl implements GoodsclassService {
    @Resource
    private GoodsclassDao goodsclassDao;

    @Override
    public List<Goodsclass> myfindAll(int appid, int shopid, String level) {
        return goodsclassDao.myfindAll(appid,shopid,level);
    }

    @Override
    public List<Goodsclass> myfindclass(int appid, int shopid, int fatherid) {
        return goodsclassDao.myfindclass(appid,shopid,fatherid);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Goodsclass queryById(Integer id) {
        return this.goodsclassDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param goodsclass 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Goodsclass> queryByPage(Goodsclass goodsclass, PageRequest pageRequest) {
        long total = this.goodsclassDao.count(goodsclass);
        return new PageImpl<>(this.goodsclassDao.queryAllByLimit(goodsclass, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param goodsclass 实例对象
     * @return 实例对象
     */
    @Override
    public Goodsclass insert(Goodsclass goodsclass) {
        this.goodsclassDao.insert(goodsclass);
        return goodsclass;
    }

    /**
     * 修改数据
     *
     * @param goodsclass 实例对象
     * @return 实例对象
     */
    @Override
    public Goodsclass update(Goodsclass goodsclass) {
        this.goodsclassDao.update(goodsclass);
        return this.queryById(goodsclass.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.goodsclassDao.deleteById(id) > 0;
    }
}
